import re
import os
import requests
import Logger


def GetStation():
    URL = "https://kyfw.12306.cn/otn/resources/js/framework/station_name.js?station_version = 1.9311"
    Logger.Print_Info("Start to download station file")
    response = requests.get(URL, verify=True)
    stations = re.findall(u'([\u4e00-\u9fa5]+)\|([A-Z]+)', response.text)
    stations = dict(stations)
    stations = str(stations)
    Write(stations)
    Logger.Print_Success("Complete")

def Write(stations):
    file = open("stations.text", "w", encoding="utf_8_sig")
    file.write(stations)
    file.close()


def Read():
    file = open("stations.text", "r", encoding="utf_8_sig")
    data = file.readline()
    file.close()
    return data


def IsStations():
    return os.path.exists("stations.text")
